<?php Kd_Web::getPage()->addReferenceScript('industryscript', '/pub/share/js/industry.js'); ?>
<?php if($this->getMultiple()): ?>
<select id="<?php echo $this->getId() ?>_industry_1"></select>
<select id="<?php echo $this->getId() ?>_industry_2"></select>
<select id="<?php echo $this->getId() ?>_industry_3"></select>
<select id="<?php echo $this->getId() ?>_industry_4"></select>
<button type="button" onclick="javascript:<?php echo $this->getId() ?>AddIndustry()"><?php echo Kd_Localize_Helper::__('share.button.add')?></button>
<div>
<ul id="<?php echo $this->getId() ?>_container" class="industry-selected-list">
</ul>
</div>
<input type="text" id="<?php echo $this->getId() ?>" value="" <?php echo $this->getValidateRuleHtml()?> style="display:none"/>
<script language="javascript" type="text/javascript">
var <?php echo $this->getId()?>_industry = new ritu.IndustrySelect('<?php echo $this->getId()?>');
function <?php echo $this->getId() ?>AddIndustry(code){
    var industryCode = code? code: <?php echo $this->getId()?>_industry.getValue();
    if(industryCode == ''){
        return;
    }

    var codes = $('input[name="<?php echo $this->getName()?>"]');
    for(var i = 0; i < codes.length; i++){
        if($(codes[i]).val() == industryCode){
            return;
        }
    }

    var id = '#<?php echo $this->getId() ?>_container';
    var html = '<li><span>' + ritu.getIndustryName(industryCode)+ '</span>';
    html += '<a class="button" href="javascript:void(0)" onclick="javascript:$(this).parent().remove()"><?php echo Kd_Localize_Helper::__('share.button.delete')?> </a>';
    html += '<input type="hidden" name="<?php echo $this->getName()?>" value="' + industryCode + '"></li>';
    $(id).append(html);
}

<?php
if(is_array($this->getValue())):
    foreach($this->getValue() as $value):
?>
<?php echo $this->getId() ?>AddIndustry('<?php echo $value['id'] ?>');
<?php
    endforeach;
endif;
?>
</script>
<?php else:if($this->getReadonly()):
?>
<span id="<?php echo $this->getId() ?>_readonly">{industry_<?php echo $this->getValue() ?>}</span>
<script language="javascript" type="text/javascript">
replaceIndustryCode('<?php echo $this->getId() ?>_readonly', null, true);
</script>
<?php else: ?>
<select id="<?php echo $this->getId() ?>_industry_1"></select>
<select id="<?php echo $this->getId() ?>_industry_2"></select>
<select id="<?php echo $this->getId() ?>_industry_3"></select>
<select id="<?php echo $this->getId() ?>_industry_4"></select>
<input type="text" id="<?php echo $this->getId() ?>" name="<?php echo $this->getName()?>" value="<?php echo $this->getValue() ?>" <?php echo $this->getValidateRuleHtml()?> style="display:none"/>
<script language="javascript" type="text/javascript">
var <?php echo $this->getId()?>_industry = new ritu.IndustrySelect('<?php echo $this->getId()?>');
</script>
<?php 
	endif;
endif; 
?>